4 ** Copyright (C) Nate Robins, 1997
5 ** Michael Wimmer, 1999
6 ** Milan Ikits, 2002-2008
7 ** Nigel Stewart, 2008-2013
9 ** visualinfo is a small utility that displays all available visuals,
10 ** aka. pixelformats, in an OpenGL system along with renderer version
11 ** information. It shows a table of all the visuals that support OpenGL
12 ** along with their capabilities. The format of the table is similar to
13 ** that of glxinfo on Unix systems:
15 ** visual ~= pixel format descriptor
16 ** id = visual id (integer from 1 - max visuals)
17 ** tp = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)
18 ** ac = acceleration (ge: generic, fu: full, no: none)
19 ** fm = format (i: integer, f: float, c: color index)
20 ** db = double buffer (y = yes)
21 ** sw = swap method (x: exchange, c: copy, u: undefined)
22 ** st = stereo (y = yes)
25 ** g = # bits of green
27 ** a = # bits of alpha
28 ** axbf = # aux buffers
29 ** dpth = # bits of depth
30 ** stcl = # bits of stencil
39 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
40 #include <OpenGL/OpenGL.h>
41 #include <OpenGL/CGLTypes.h>
42 #elif !defined(__HAIKU__)
48 # define glewGetContext() (&_glewctx)
50 WGLEWContext _wglewctx
;
51 # define wglewGetContext() (&_wglewctx)
52 # elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
53 GLXEWContext _glxewctx
;
54 # define glxewGetContext() (&_glxewctx)
58 typedef struct GLContextStruct
64 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
65 CGLContextObj ctx
, octx
;
66 #elif !defined(__HAIKU__)
75 void InitContext (GLContext
* ctx
);
76 GLboolean
CreateContext (GLContext
* ctx
);
77 void DestroyContext (GLContext
* ctx
);
78 void VisualInfo (GLContext
* ctx
);
79 void PrintExtensions (const char* s
);
80 GLboolean
ParseArgs (int argc
, char** argv
);
83 int displaystdout
= 0;
93 main (int argc
, char** argv
)
98 /* ---------------------------------------------------------------------- */
100 if (GL_TRUE
== ParseArgs(argc
-1, argv
+1))
103 fprintf(stderr
, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
104 fprintf(stderr
, " -a: show all visuals\n");
105 fprintf(stderr
, " -s: display to stdout instead of visualinfo.txt\n");
106 fprintf(stderr
, " -pf <id>: use given pixelformat\n");
107 fprintf(stderr
, " -h: this screen\n");
109 fprintf(stderr
, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");
110 fprintf(stderr
, " -h: this screen\n");
111 fprintf(stderr
, " -display <display>: use given display\n");
112 fprintf(stderr
, " -visual <id>: use given visual\n");
117 /* ---------------------------------------------------------------------- */
118 /* create OpenGL rendering context */
120 if (GL_TRUE
== CreateContext(&ctx
))
122 fprintf(stderr
, "Error: CreateContext failed\n");
123 DestroyContext(&ctx
);
127 /* ---------------------------------------------------------------------- */
128 /* initialize GLEW */
129 glewExperimental
= GL_TRUE
;
131 err
= glewContextInit(glewGetContext());
133 err
= err
|| wglewContextInit(wglewGetContext());
134 # elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
135 err
= err
|| glxewContextInit(glxewGetContext());
142 fprintf(stderr
, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err
));
143 DestroyContext(&ctx
);
147 /* ---------------------------------------------------------------------- */
152 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
153 if (fopen_s(&file
, "visualinfo.txt", "w") != 0)
156 file
= fopen("visualinfo.txt", "w");
165 /* ---------------------------------------------------------------------- */
166 /* output header information */
167 /* OpenGL extensions */
168 fprintf(file
, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR
));
169 fprintf(file
, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER
));
170 fprintf(file
, "OpenGL version string: %s\n", glGetString(GL_VERSION
));
171 fprintf(file
, "OpenGL extensions (GL_): \n");
172 PrintExtensions((const char*)glGetString(GL_EXTENSIONS
));
176 fprintf(file
, "GLU version string: %s\n", gluGetString(GLU_VERSION
));
177 fprintf(file
, "GLU extensions (GLU_): \n");
178 PrintExtensions((const char*)gluGetString(GLU_EXTENSIONS
));
181 /* ---------------------------------------------------------------------- */
182 /* extensions string */
185 if (WGLEW_ARB_extensions_string
|| WGLEW_EXT_extensions_string
)
187 fprintf(file
, "WGL extensions (WGL_): \n");
188 PrintExtensions(wglGetExtensionsStringARB
?
189 (const char*)wglGetExtensionsStringARB(ctx
.dc
) :
190 (const char*)wglGetExtensionsStringEXT());
192 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
194 #elif defined(__HAIKU__)
200 fprintf(file
, "GLX extensions (GLX_): \n");
201 PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),
202 DefaultScreen(glXGetCurrentDisplay())));
205 /* ---------------------------------------------------------------------- */
206 /* enumerate all the formats */
209 /* ---------------------------------------------------------------------- */
210 /* release resources */
211 DestroyContext(&ctx
);
217 /* do the magic to separate all extensions with comma's, except
218 for the last one that _may_ terminate in a space. */
219 void PrintExtensions (const char* s
)
231 if (*(s
+1) != '\0') {
236 else /* zoinks! last one terminated in a space! */
244 fprintf(file
, " %s\n", t
);
247 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
248 strcpy_s(t
, sizeof(t
), p
);
256 fprintf(file
, " %s.\n", t
);
259 /* ---------------------------------------------------------------------- */
264 VisualInfoARB (GLContext
* ctx
)
266 int attrib
[32], value
[32], n_attrib
, n_pbuffer
=0, n_float
=0;
270 /* to get pbuffer capable pixel formats */
271 attrib
[0] = WGL_DRAW_TO_PBUFFER_ARB
;
274 wglChoosePixelFormatARB(ctx
->dc
, attrib
, 0, 1, &pf
, &c
);
275 /* query number of pixel formats */
276 attrib
[0] = WGL_NUMBER_PIXEL_FORMATS_ARB
;
277 wglGetPixelFormatAttribivARB(ctx
->dc
, 0, 0, 1, attrib
, value
);
282 attrib
[0] = WGL_SUPPORT_OPENGL_ARB
;
283 attrib
[1] = WGL_DRAW_TO_WINDOW_ARB
;
284 attrib
[2] = WGL_DRAW_TO_BITMAP_ARB
;
285 attrib
[3] = WGL_ACCELERATION_ARB
;
286 /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
287 attrib
[4] = WGL_SWAP_METHOD_ARB
;
288 /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
289 attrib
[5] = WGL_DOUBLE_BUFFER_ARB
;
290 attrib
[6] = WGL_STEREO_ARB
;
291 attrib
[7] = WGL_PIXEL_TYPE_ARB
;
292 /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
293 WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
294 /* Color buffer information */
295 attrib
[8] = WGL_COLOR_BITS_ARB
;
296 attrib
[9] = WGL_RED_BITS_ARB
;
297 attrib
[10] = WGL_GREEN_BITS_ARB
;
298 attrib
[11] = WGL_BLUE_BITS_ARB
;
299 attrib
[12] = WGL_ALPHA_BITS_ARB
;
300 /* Accumulation buffer information */
301 attrib
[13] = WGL_ACCUM_BITS_ARB
;
302 attrib
[14] = WGL_ACCUM_RED_BITS_ARB
;
303 attrib
[15] = WGL_ACCUM_GREEN_BITS_ARB
;
304 attrib
[16] = WGL_ACCUM_BLUE_BITS_ARB
;
305 attrib
[17] = WGL_ACCUM_ALPHA_BITS_ARB
;
306 /* Depth, stencil, and aux buffer information */
307 attrib
[18] = WGL_DEPTH_BITS_ARB
;
308 attrib
[19] = WGL_STENCIL_BITS_ARB
;
309 attrib
[20] = WGL_AUX_BUFFERS_ARB
;
310 /* Layer information */
311 attrib
[21] = WGL_NUMBER_OVERLAYS_ARB
;
312 attrib
[22] = WGL_NUMBER_UNDERLAYS_ARB
;
313 attrib
[23] = WGL_SWAP_LAYER_BUFFERS_ARB
;
314 attrib
[24] = WGL_SAMPLES_ARB
;
315 attrib
[25] = WGL_SUPPORT_GDI_ARB
;
317 if (WGLEW_ARB_pbuffer
)
319 attrib
[n_attrib
] = WGL_DRAW_TO_PBUFFER_ARB
;
320 n_pbuffer
= n_attrib
;
323 if (WGLEW_NV_float_buffer
)
325 attrib
[n_attrib
] = WGL_FLOAT_COMPONENTS_NV
;
332 /* print table header */
333 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
334 fprintf(file
, " | | visual | color | ax dp st | accum | layer |\n");
335 fprintf(file
, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
336 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
337 /* loop through all the pixel formats */
338 for(i
= 1; i
<= maxpf
; i
++)
340 wglGetPixelFormatAttribivARB(ctx
->dc
, i
, 0, n_attrib
, attrib
, value
);
341 /* only describe this format if it supports OpenGL */
342 if (!value
[0]) continue;
343 /* by default show only fully accelerated window or pbuffer capable visuals */
345 && ((value
[2] && !value
[1])
346 || (!WGLEW_ARB_pbuffer
|| !value
[n_pbuffer
])
347 || (value
[3] != WGL_FULL_ACCELERATION_ARB
))) continue;
348 /* print out the information for this visual */
350 fprintf(file
, " |% 4d | ", i
);
354 if (WGLEW_ARB_pbuffer
&& value
[n_pbuffer
]) fprintf(file
, "wp ");
355 else fprintf(file
, "wn ");
359 if (value
[2]) fprintf(file
, "bm ");
360 else if (WGLEW_ARB_pbuffer
&& value
[n_pbuffer
]) fprintf(file
, "pb ");
363 fprintf(file
, "%s ", value
[3] == WGL_FULL_ACCELERATION_ARB
? "fu" :
364 value
[3] == WGL_GENERIC_ACCELERATION_ARB
? "ge" :
365 value
[3] == WGL_NO_ACCELERATION_ARB
? "no" : ". ");
367 fprintf(file
, " %c ", value
[25] ? 'y' : '.');
369 if (WGLEW_NV_float_buffer
&& value
[n_float
]) fprintf(file
, " f ");
370 else if (WGLEW_ATI_pixel_format_float
&& value
[7] == WGL_TYPE_RGBA_FLOAT_ATI
) fprintf(file
, " f ");
371 else if (value
[7] == WGL_TYPE_RGBA_ARB
) fprintf(file
, " i ");
372 else if (value
[7] == WGL_TYPE_COLORINDEX_ARB
) fprintf(file
, " c ");
373 else if (value
[7] == WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT
) fprintf(file
," p ");
374 else fprintf(file
," ? ");
376 fprintf(file
, " %c ", value
[5] ? 'y' : '.');
378 if (value
[4] == WGL_SWAP_EXCHANGE_ARB
) fprintf(file
, " x ");
379 else if (value
[4] == WGL_SWAP_COPY_ARB
) fprintf(file
, " c ");
380 else if (value
[4] == WGL_SWAP_UNDEFINED_ARB
) fprintf(file
, " . ");
381 else fprintf(file
, " . ");
383 fprintf(file
, " %c ", value
[6] ? 'y' : '.');
386 fprintf(file
, "%2d | ", value
[24]);
388 fprintf(file
, " . | ");
390 if (value
[8]) fprintf(file
, "%3d ", value
[8]);
391 else fprintf(file
, " . ");
393 if (value
[9]) fprintf(file
, "%2d ", value
[9]);
394 else fprintf(file
, " . ");
396 if (value
[10]) fprintf(file
, "%2d ", value
[10]);
397 else fprintf(file
, " . ");
399 if (value
[11]) fprintf(file
, "%2d ", value
[11]);
400 else fprintf(file
, " . ");
402 if (value
[12]) fprintf(file
, "%2d | ", value
[12]);
403 else fprintf(file
, " . | ");
405 if (value
[20]) fprintf(file
, "%2d ", value
[20]);
406 else fprintf(file
, " . ");
408 if (value
[18]) fprintf(file
, "%2d ", value
[18]);
409 else fprintf(file
, " . ");
411 if (value
[19]) fprintf(file
, "%2d | ", value
[19]);
412 else fprintf(file
, " . | ");
414 if (value
[13]) fprintf(file
, "%3d ", value
[13]);
415 else fprintf(file
, " . ");
417 if (value
[14]) fprintf(file
, "%2d ", value
[14]);
418 else fprintf(file
, " . ");
420 if (value
[15]) fprintf(file
, "%2d ", value
[15]);
421 else fprintf(file
, " . ");
423 if (value
[16]) fprintf(file
, "%2d ", value
[16]);
424 else fprintf(file
, " . ");
426 if (value
[17]) fprintf(file
, "%2d | ", value
[17]);
427 else fprintf(file
, " . | ");
429 if (value
[21]) fprintf(file
, "%2d ", value
[21]);
430 else fprintf(file
, " . ");
432 if (value
[22]) fprintf(file
, "%2d ", value
[22]);
433 else fprintf(file
, " . ");
435 if (value
[23]) fprintf(file
, "y ");
436 else fprintf(file
, " . ");
437 fprintf(file
, "|\n");
439 /* print table footer */
440 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
441 fprintf(file
, " | | visual | color | ax dp st | accum | layer |\n");
442 fprintf(file
, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
443 fprintf(file
, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
449 /* loop through all the pixel formats */
450 for(i
= 1; i
<= maxpf
; i
++)
452 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
453 /* only describe this format if it supports OpenGL */
454 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
455 || (drawableonly
&& !(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
))) continue;
456 fprintf(file
, "Visual ID: %2d depth=%d class=%s\n", i
, pfd
.cDepthBits
,
457 pfd
.cColorBits
<= 8 ? "PseudoColor" : "TrueColor");
458 fprintf(file
, " bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", pfd
.cColorBits
, pfd
.bReserved
, pfd
.iPixelType
== PFD_TYPE_RGBA
? "rgba" : "ci", pfd
.dwFlags
& PFD_DOUBLEBUFFER
, pfd
.dwFlags
& PFD_STEREO
);
459 fprintf(file
, " generic=%d generic accelerated=%d\n", (pfd
.dwFlags
& PFD_GENERIC_FORMAT
) == PFD_GENERIC_FORMAT
, (pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
) == PFD_GENERIC_ACCELERATED
);
460 fprintf(file
, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cRedBits
, pfd
.cGreenBits
, pfd
.cBlueBits
, pfd
.cAlphaBits
);
461 fprintf(file
, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd
.cAuxBuffers
, pfd
.cDepthBits
, pfd
.cStencilBits
);
462 fprintf(file
, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cAccumRedBits
, pfd
.cAccumGreenBits
, pfd
.cAccumBlueBits
, pfd
.cAccumAlphaBits
);
463 fprintf(file
, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
464 fprintf(file
, " Opaque.\n");
471 VisualInfoGDI (GLContext
* ctx
)
474 PIXELFORMATDESCRIPTOR pfd
;
476 /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
477 number of pixel formats */
478 maxpf
= DescribePixelFormat(ctx
->dc
, 1, 0, NULL
);
482 fprintf(file
, "-----------------------------------------------------------------------------\n");
483 fprintf(file
, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
484 fprintf(file
, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
485 fprintf(file
, "-----------------------------------------------------------------------------\n");
487 /* loop through all the pixel formats */
488 for(i
= 1; i
<= maxpf
; i
++)
490 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
491 /* only describe this format if it supports OpenGL */
492 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
493 || (drawableonly
&& (pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
))) continue;
494 /* other criteria could be tested here for actual pixel format
495 choosing in an application:
497 for (...each pixel format...) {
498 if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
499 pfd.dwFlags & PFD_DOUBLEBUFFER &&
500 pfd.cDepthBits >= 24 &&
501 pfd.cColorBits >= 24)
506 ... not found so exit ...
508 ... found so use it ...
510 /* print out the information for this pixel format */
511 fprintf(file
, "0x%02x ", i
);
512 fprintf(file
, "%3d ", pfd
.cColorBits
);
513 if(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
) fprintf(file
, "wn ");
514 else if(pfd
.dwFlags
& PFD_DRAW_TO_BITMAP
) fprintf(file
, "bm ");
515 else fprintf(file
, "pb ");
516 /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
517 fprintf(file
, " . ");
518 fprintf(file
, "%3d ", pfd
.cColorBits
);
519 /* bReserved field indicates number of over/underlays */
520 if(pfd
.bReserved
) fprintf(file
, " %d ", pfd
.bReserved
);
521 else fprintf(file
, " . ");
522 fprintf(file
, " %c ", pfd
.iPixelType
== PFD_TYPE_RGBA
? 'r' : 'c');
523 fprintf(file
, "%c ", pfd
.dwFlags
& PFD_DOUBLEBUFFER
? 'y' : '.');
524 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_STEREO
? 'y' : '.');
526 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_GENERIC_FORMAT
? 'y' : '.');
527 fprintf(file
, " %c ", pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
? 'y' : '.');
528 if(pfd
.cRedBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
529 fprintf(file
, "%2d ", pfd
.cRedBits
);
530 else fprintf(file
, " . ");
531 if(pfd
.cGreenBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
532 fprintf(file
, "%2d ", pfd
.cGreenBits
);
533 else fprintf(file
, " . ");
534 if(pfd
.cBlueBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
535 fprintf(file
, "%2d ", pfd
.cBlueBits
);
536 else fprintf(file
, " . ");
537 if(pfd
.cAlphaBits
&& pfd
.iPixelType
== PFD_TYPE_RGBA
)
538 fprintf(file
, "%2d ", pfd
.cAlphaBits
);
539 else fprintf(file
, " . ");
540 if(pfd
.cAuxBuffers
) fprintf(file
, "%2d ", pfd
.cAuxBuffers
);
541 else fprintf(file
, " . ");
542 if(pfd
.cDepthBits
) fprintf(file
, "%2d ", pfd
.cDepthBits
);
543 else fprintf(file
, " . ");
544 if(pfd
.cStencilBits
) fprintf(file
, "%2d ", pfd
.cStencilBits
);
545 else fprintf(file
, " . ");
546 if(pfd
.cAccumBits
) fprintf(file
, "%3d ", pfd
.cAccumBits
);
547 else fprintf(file
, " . ");
548 if(pfd
.cAccumRedBits
) fprintf(file
, "%2d ", pfd
.cAccumRedBits
);
549 else fprintf(file
, " . ");
550 if(pfd
.cAccumGreenBits
) fprintf(file
, "%2d ", pfd
.cAccumGreenBits
);
551 else fprintf(file
, " . ");
552 if(pfd
.cAccumBlueBits
) fprintf(file
, "%2d ", pfd
.cAccumBlueBits
);
553 else fprintf(file
, " . ");
554 if(pfd
.cAccumAlphaBits
) fprintf(file
, "%2d ", pfd
.cAccumAlphaBits
);
555 else fprintf(file
, " . ");
556 /* no multisample in win32 */
557 fprintf(file
, " . .\n");
559 /* print table footer */
560 fprintf(file
, "-----------------------------------------------------------------------------\n");
561 fprintf(file
, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
562 fprintf(file
, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
563 fprintf(file
, "-----------------------------------------------------------------------------\n");
568 /* loop through all the pixel formats */
569 for(i
= 1; i
<= maxpf
; i
++)
571 DescribePixelFormat(ctx
->dc
, i
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
572 /* only describe this format if it supports OpenGL */
573 if(!(pfd
.dwFlags
& PFD_SUPPORT_OPENGL
)
574 || (drawableonly
&& !(pfd
.dwFlags
& PFD_DRAW_TO_WINDOW
))) continue;
575 fprintf(file
, "Visual ID: %2d depth=%d class=%s\n", i
, pfd
.cDepthBits
,
576 pfd
.cColorBits
<= 8 ? "PseudoColor" : "TrueColor");
577 fprintf(file
, " bufferSize=%d level=%d renderType=%s doubleBuffer=%ld stereo=%ld\n", pfd
.cColorBits
, pfd
.bReserved
, pfd
.iPixelType
== PFD_TYPE_RGBA
? "rgba" : "ci", pfd
.dwFlags
& PFD_DOUBLEBUFFER
, pfd
.dwFlags
& PFD_STEREO
);
578 fprintf(file
, " generic=%d generic accelerated=%d\n", (pfd
.dwFlags
& PFD_GENERIC_FORMAT
) == PFD_GENERIC_FORMAT
, (pfd
.dwFlags
& PFD_GENERIC_ACCELERATED
) == PFD_GENERIC_ACCELERATED
);
579 fprintf(file
, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cRedBits
, pfd
.cGreenBits
, pfd
.cBlueBits
, pfd
.cAlphaBits
);
580 fprintf(file
, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd
.cAuxBuffers
, pfd
.cDepthBits
, pfd
.cStencilBits
);
581 fprintf(file
, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd
.cAccumRedBits
, pfd
.cAccumGreenBits
, pfd
.cAccumBlueBits
, pfd
.cAccumAlphaBits
);
582 fprintf(file
, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
583 fprintf(file
, " Opaque.\n");
589 VisualInfo (GLContext
* ctx
)
591 if (WGLEW_ARB_pixel_format
)
597 /* ---------------------------------------------------------------------- */
599 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
602 VisualInfo (GLContext
* __attribute__((__unused__
)) ctx
)
605 int attrib[] = { AGL_RGBA, AGL_NONE };
608 pf = aglChoosePixelFormat(NULL, 0, attrib);
611 aglDescribePixelFormat(pf, GL_RGBA, &value);
612 fprintf(stderr, "%d\n", value);
613 pf = aglNextPixelFormat(pf);
618 /* ---------------------------------------------------------------------- */
620 #elif defined(__HAIKU__)
623 VisualInfo (GLContext
* ctx
)
631 VisualInfo (GLContext
* ctx
)
637 fbc
= glXGetFBConfigs(ctx
->dpy
, DefaultScreen(ctx
->dpy
), &n_fbc
);
643 /* print table header */
644 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
645 fprintf(file
, " | | visual | color | ax dp st | accum | ms | cav |\n");
646 fprintf(file
, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
647 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
648 /* loop through all the fbcs */
649 for (i
=0; i
<n_fbc
; i
++)
651 /* print out the information for this fbc */
653 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_FBCONFIG_ID
, &value
);
656 fprintf(file
, "| ? |");
660 fprintf(file
, " |% 4d | ", value
);
663 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DRAWABLE_TYPE
, &value
);
666 fprintf(file
, " ? ");
670 if (value
& GLX_WINDOW_BIT
)
672 if (value
& GLX_PBUFFER_BIT
)
674 fprintf(file
, "wp ");
678 fprintf(file
, "wn ");
683 if (value
& GLX_PBUFFER_BIT
)
685 fprintf(file
, "pb ");
687 else if (value
& GLX_PIXMAP_BIT
)
689 fprintf(file
, "pm ");
693 fprintf(file
, " ? ");
698 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_X_RENDERABLE
, &value
);
701 fprintf(file
, " ? ");
705 fprintf(file
, value
? " y " : " n ");
708 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_X_VISUAL_TYPE
, &value
);
711 fprintf(file
, " ? ");
715 if (GLX_TRUE_COLOR
== value
)
716 fprintf(file
, "tc ");
717 else if (GLX_DIRECT_COLOR
== value
)
718 fprintf(file
, "dc ");
719 else if (GLX_PSEUDO_COLOR
== value
)
720 fprintf(file
, "pc ");
721 else if (GLX_STATIC_COLOR
== value
)
722 fprintf(file
, "sc ");
723 else if (GLX_GRAY_SCALE
== value
)
724 fprintf(file
, "gs ");
725 else if (GLX_STATIC_GRAY
== value
)
726 fprintf(file
, "sg ");
727 else if (GLX_X_VISUAL_TYPE
== value
)
728 fprintf(file
, " . ");
730 fprintf(file
, " ? ");
733 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_RENDER_TYPE
, &value
);
736 fprintf(file
, " ? ");
740 if (GLXEW_NV_float_buffer
)
743 ret2
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_FLOAT_COMPONENTS_NV
, &value2
);
744 if (Success
== ret2
&& GL_TRUE
== value2
)
746 fprintf(file
, " f ");
748 else if (value
& GLX_RGBA_BIT
)
749 fprintf(file
, " i ");
750 else if (value
& GLX_COLOR_INDEX_BIT
)
751 fprintf(file
, " c ");
753 fprintf(file
, " ? ");
757 if (value
& GLX_RGBA_FLOAT_ATI_BIT
)
758 fprintf(file
, " f ");
759 else if (value
& GLX_RGBA_BIT
)
760 fprintf(file
, " i ");
761 else if (value
& GLX_COLOR_INDEX_BIT
)
762 fprintf(file
, " c ");
764 fprintf(file
, " ? ");
768 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DOUBLEBUFFER
, &value
);
769 fprintf(file
, " %c ", Success
!= ret
? '?' : (value
? 'y' : '.'));
771 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_STEREO
, &value
);
772 fprintf(file
, " %c ", Success
!= ret
? '?' : (value
? 'y' : '.'));
774 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_LEVEL
, &value
);
777 fprintf(file
, " ? ");
781 fprintf(file
, "%2d ", value
);
784 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_TRANSPARENT_TYPE
, &value
);
787 fprintf(file
, " ? | ");
791 if (GLX_TRANSPARENT_RGB
== value
)
792 fprintf(file
, " r | ");
793 else if (GLX_TRANSPARENT_INDEX
== value
)
794 fprintf(file
, " i | ");
795 else if (GLX_NONE
== value
)
796 fprintf(file
, " . | ");
798 fprintf(file
, " ? | ");
801 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_BUFFER_SIZE
, &value
);
804 fprintf(file
, " ? ");
809 fprintf(file
, "%3d ", value
);
811 fprintf(file
, " . ");
814 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_RED_SIZE
, &value
);
817 fprintf(file
, " ? ");
822 fprintf(file
, "%2d ", value
);
824 fprintf(file
, " . ");
827 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_GREEN_SIZE
, &value
);
830 fprintf(file
, " ? ");
835 fprintf(file
, "%2d ", value
);
837 fprintf(file
, " . ");
840 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_BLUE_SIZE
, &value
);
843 fprintf(file
, " ? ");
848 fprintf(file
, "%2d ", value
);
850 fprintf(file
, " . ");
853 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ALPHA_SIZE
, &value
);
856 fprintf(file
, " ? | ");
861 fprintf(file
, "%2d | ", value
);
863 fprintf(file
, " . | ");
866 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_AUX_BUFFERS
, &value
);
869 fprintf(file
, " ? ");
874 fprintf(file
, "%2d ", value
);
876 fprintf(file
, " . ");
879 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_DEPTH_SIZE
, &value
);
882 fprintf(file
, " ? ");
887 fprintf(file
, "%2d ", value
);
889 fprintf(file
, " . ");
892 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_STENCIL_SIZE
, &value
);
895 fprintf(file
, " ? | ");
900 fprintf(file
, "%2d | ", value
);
902 fprintf(file
, " . | ");
905 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_RED_SIZE
, &value
);
908 fprintf(file
, " ? ");
913 fprintf(file
, "%2d ", value
);
915 fprintf(file
, " . ");
917 /* accum green size */
918 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_GREEN_SIZE
, &value
);
921 fprintf(file
, " ? ");
926 fprintf(file
, "%2d ", value
);
928 fprintf(file
, " . ");
930 /* accum blue size */
931 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_BLUE_SIZE
, &value
);
934 fprintf(file
, " ? ");
939 fprintf(file
, "%2d ", value
);
941 fprintf(file
, " . ");
943 /* accum alpha size */
944 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_ACCUM_ALPHA_SIZE
, &value
);
947 fprintf(file
, " ? | ");
952 fprintf(file
, "%2d | ", value
);
954 fprintf(file
, " . | ");
957 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_SAMPLES
, &value
);
960 fprintf(file
, " ? ");
964 fprintf(file
, "%2d ", value
);
966 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_SAMPLE_BUFFERS
, &value
);
969 fprintf(file
, " ? | ");
973 fprintf(file
, "%2d | ", value
);
976 ret
= glXGetFBConfigAttrib(ctx
->dpy
, fbc
[i
], GLX_CONFIG_CAVEAT
, &value
);
979 fprintf(file
, "???? |");
983 if (GLX_NONE
== value
)
984 fprintf(file
, "none |\n");
985 else if (GLX_SLOW_CONFIG
== value
)
986 fprintf(file
, "slow |\n");
987 else if (GLX_NON_CONFORMANT_CONFIG
== value
)
988 fprintf(file
, "ncft |\n");
990 fprintf(file
, "???? |\n");
993 /* print table footer */
994 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
995 fprintf(file
, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
996 fprintf(file
, " | | visual | color | ax dp st | accum | ms | cav |\n");
997 fprintf(file
, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
1004 /* ------------------------------------------------------------------------ */
1008 void InitContext (GLContext
* ctx
)
1015 GLboolean
CreateContext (GLContext
* ctx
)
1018 PIXELFORMATDESCRIPTOR pfd
;
1019 /* check for input */
1020 if (NULL
== ctx
) return GL_TRUE
;
1021 /* register window class */
1022 ZeroMemory(&wc
, sizeof(WNDCLASS
));
1023 wc
.hInstance
= GetModuleHandle(NULL
);
1024 wc
.lpfnWndProc
= DefWindowProc
;
1025 wc
.lpszClassName
= "GLEW";
1026 if (0 == RegisterClass(&wc
)) return GL_TRUE
;
1028 ctx
->wnd
= CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT
, CW_USEDEFAULT
,
1029 CW_USEDEFAULT
, CW_USEDEFAULT
, NULL
, NULL
,
1030 GetModuleHandle(NULL
), NULL
);
1031 if (NULL
== ctx
->wnd
) return GL_TRUE
;
1032 /* get the device context */
1033 ctx
->dc
= GetDC(ctx
->wnd
);
1034 if (NULL
== ctx
->dc
) return GL_TRUE
;
1035 /* find pixel format */
1036 ZeroMemory(&pfd
, sizeof(PIXELFORMATDESCRIPTOR
));
1037 if (visual
== -1) /* find default */
1039 pfd
.nSize
= sizeof(PIXELFORMATDESCRIPTOR
);
1041 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
1042 visual
= ChoosePixelFormat(ctx
->dc
, &pfd
);
1043 if (0 == visual
) return GL_TRUE
;
1045 /* set the pixel format for the dc */
1046 if (FALSE
== SetPixelFormat(ctx
->dc
, visual
, &pfd
)) return GL_TRUE
;
1047 /* create rendering context */
1048 ctx
->rc
= wglCreateContext(ctx
->dc
);
1049 if (NULL
== ctx
->rc
) return GL_TRUE
;
1050 if (FALSE
== wglMakeCurrent(ctx
->dc
, ctx
->rc
)) return GL_TRUE
;
1054 void DestroyContext (GLContext
* ctx
)
1056 if (NULL
== ctx
) return;
1057 if (NULL
!= ctx
->rc
) wglMakeCurrent(NULL
, NULL
);
1058 if (NULL
!= ctx
->rc
) wglDeleteContext(wglGetCurrentContext());
1059 if (NULL
!= ctx
->wnd
&& NULL
!= ctx
->dc
) ReleaseDC(ctx
->wnd
, ctx
->dc
);
1060 if (NULL
!= ctx
->wnd
) DestroyWindow(ctx
->wnd
);
1061 UnregisterClass("GLEW", GetModuleHandle(NULL
));
1064 /* ------------------------------------------------------------------------ */
1066 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
1068 void InitContext (GLContext
* ctx
)
1074 GLboolean
CreateContext (GLContext
* ctx
)
1076 CGLPixelFormatAttribute attrib
[] = { kCGLPFAAccelerated
, 0 };
1077 CGLPixelFormatObj pf
;
1081 if (NULL
== ctx
) return GL_TRUE
;
1082 error
= CGLChoosePixelFormat(attrib
, &pf
, &npix
);
1083 if (error
) return GL_TRUE
;
1084 error
= CGLCreateContext(pf
, NULL
, &ctx
->ctx
);
1085 if (error
) return GL_TRUE
;
1086 CGLReleasePixelFormat(pf
);
1087 ctx
->octx
= CGLGetCurrentContext();
1088 error
= CGLSetCurrentContext(ctx
->ctx
);
1089 if (error
) return GL_TRUE
;
1093 void DestroyContext (GLContext
* ctx
)
1095 if (NULL
== ctx
) return;
1096 CGLSetCurrentContext(ctx
->octx
);
1097 if (NULL
!= ctx
->ctx
) CGLReleaseContext(ctx
->ctx
);
1100 /* ------------------------------------------------------------------------ */
1102 #elif defined(__HAIKU__)
1105 InitContext (GLContext
* ctx
)
1111 CreateContext (GLContext
* ctx
)
1118 DestroyContext (GLContext
* ctx
)
1123 /* ------------------------------------------------------------------------ */
1125 #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1127 void InitContext (GLContext
* ctx
)
1136 GLboolean
CreateContext (GLContext
* ctx
)
1138 int attrib
[] = { GLX_RGBA
, GLX_DOUBLEBUFFER
, None
};
1140 XSetWindowAttributes swa
;
1142 if (NULL
== ctx
) return GL_TRUE
;
1144 ctx
->dpy
= XOpenDisplay(display
);
1145 if (NULL
== ctx
->dpy
) return GL_TRUE
;
1147 if (!glXQueryExtension(ctx
->dpy
, &erb
, &evb
)) return GL_TRUE
;
1149 ctx
->vi
= glXChooseVisual(ctx
->dpy
, DefaultScreen(ctx
->dpy
), attrib
);
1150 if (NULL
== ctx
->vi
) return GL_TRUE
;
1151 /* create context */
1152 ctx
->ctx
= glXCreateContext(ctx
->dpy
, ctx
->vi
, None
, True
);
1153 if (NULL
== ctx
->ctx
) return GL_TRUE
;
1155 /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
1156 ctx
->cmap
= XCreateColormap(ctx
->dpy
, RootWindow(ctx
->dpy
, ctx
->vi
->screen
),
1157 ctx
->vi
->visual
, AllocNone
);
1158 swa
.border_pixel
= 0;
1159 swa
.colormap
= ctx
->cmap
;
1160 ctx
->wnd
= XCreateWindow(ctx
->dpy
, RootWindow(ctx
->dpy
, ctx
->vi
->screen
),
1161 0, 0, 1, 1, 0, ctx
->vi
->depth
, InputOutput
, ctx
->vi
->visual
,
1162 CWBorderPixel
| CWColormap
, &swa
);
1163 /* make context current */
1164 if (!glXMakeCurrent(ctx
->dpy
, ctx
->wnd
, ctx
->ctx
)) return GL_TRUE
;
1168 void DestroyContext (GLContext
* ctx
)
1170 if (NULL
!= ctx
->dpy
&& NULL
!= ctx
->ctx
) glXDestroyContext(ctx
->dpy
, ctx
->ctx
);
1171 if (NULL
!= ctx
->dpy
&& 0 != ctx
->wnd
) XDestroyWindow(ctx
->dpy
, ctx
->wnd
);
1172 if (NULL
!= ctx
->dpy
&& 0 != ctx
->cmap
) XFreeColormap(ctx
->dpy
, ctx
->cmap
);
1173 if (NULL
!= ctx
->vi
) XFree(ctx
->vi
);
1174 if (NULL
!= ctx
->dpy
) XCloseDisplay(ctx
->dpy
);
1177 #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
1179 GLboolean
ParseArgs (int argc
, char** argv
)
1185 if (!strcmp(argv
[p
], "-pf") || !strcmp(argv
[p
], "-pixelformat"))
1187 if (++p
>= argc
) return GL_TRUE
;
1189 visual
= strtol(argv
[p
], NULL
, 0);
1191 else if (!strcmp(argv
[p
], "-a"))
1195 else if (!strcmp(argv
[p
], "-s"))
1199 else if (!strcmp(argv
[p
], "-h"))
1206 if (!strcmp(argv
[p
], "-display"))
1208 if (++p
>= argc
) return GL_TRUE
;
1211 else if (!strcmp(argv
[p
], "-visual"))
1213 if (++p
>= argc
) return GL_TRUE
;
1214 visual
= (int)strtol(argv
[p
], NULL
, 0);
1216 else if (!strcmp(argv
[p
], "-h"))